
from QCommand import QCommand, CmdIDGen
from Cube.utility.SerialNumberGen import SerialNumberGen
# event
from EventDefine import event_QCMD_CLIENTSETUP

class QCmdClientSetup(QCommand):
    CMDID = CmdIDGen()
    CMDNAME = "QCmdClientSetup"
    # setup param encode
    paramIDGen = SerialNumberGen().Gen
    param_mapNamem = paramIDGen()
    param_mapChecksum = paramIDGen()
    param_clientMemberID = paramIDGen()
    param_syncData = paramIDGen()

    def Send(self, mapNamem, mapChecksum, clientMemberID, syncData, LinkID):
        # encode param
        param = {QCmdClientSetup.param_mapNamem:mapNamem,
                 QCmdClientSetup.param_mapChecksum:mapChecksum,
                 QCmdClientSetup.param_clientMemberID:clientMemberID,
                 QCmdClientSetup.param_syncData:syncData
                 }
        QCommand.SendDirectly(self, memberID = 0, param = param, LinkID = LinkID)

    def Handle(self, memberID, param):
        # decode param
        mapNamem = param[QCmdClientSetup.param_mapNamem]
        mapChecksum = param[QCmdClientSetup.param_mapChecksum]
        clientMemberID = param[QCmdClientSetup.param_clientMemberID]
        syncData = param[QCmdClientSetup.param_syncData]
        # raise event
        messenger.send(event_QCMD_CLIENTSETUP, [mapNamem, mapChecksum, clientMemberID, syncData])
